package com.zhang.apipassenger.controller;

// import com.zhang.internalcommon.dto.VerificationCodeDTO;
import com.zhang.apipassenger.request.CheckVerificationCodeDTO;
import com.zhang.apipassenger.request.SendVerificationCodeDTO;
import com.zhang.apipassenger.service.VerificationCodeService;
import com.zhang.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class VerificationCodeController {

	@Autowired
	private VerificationCodeService verificationCodeService;

	@PostMapping("/verification-code")
	public ResponseResult verificationCode(@Validated @RequestBody SendVerificationCodeDTO verificationCodeDTO) {
		String passengerPhone = verificationCodeDTO.getPassengerPhone();
		ResponseResult result = verificationCodeService.generateVerificationCode(passengerPhone);
		return result;
	}

	@PostMapping("/verification-code-check")
	public ResponseResult verificationCodeCheck(@Validated @RequestBody CheckVerificationCodeDTO verificationCodeDTO) {
			String passengerPhone = verificationCodeDTO.getPassengerPhone();
		String verificationCode = verificationCodeDTO.getVerificationCode();
		ResponseResult responseResult = verificationCodeService.checkVerificationCode(passengerPhone, verificationCode);
		return responseResult;
	}

	@GetMapping("/authTest")
	public ResponseResult authTest() {
		return ResponseResult.success("auth test");
	}

	@GetMapping("/noauthTest")
	public ResponseResult noAuthTest() {
		return ResponseResult.success("noauth test");
	}
}
